<?
class Util 
{
    function Util() 
    {
    
    }

/**
 * Post to a HTTP URL with the request string.
 *
 * @param url is the url to post to
 * @requestString is the request string to post to the url
 * sendHttpPost(String url, String sData, int timeout, boolean verbose)
 */
function sendHttpPost($url,$sData,$verbose)
{
  if ($verbose) {
      echo("<br>URL: ".$url);
      echo("<br>Send to host:\r\n".$sData);
  }

  $http = new Http();
  $filename = "response_".uniqid('').".xml";
  $error = $http->POST($url,$sData,"",STORAGE.$filename);

  if(strlen($error)>0)
  {
    @unlink(STORAGE.$filename);
    return $error;  
  }
 
  $sResult=file_get_contents(STORAGE.$filename); 

  if ($verbose) echo("<br>Receive from host:\r\n".$sResult);

  @unlink(STORAGE.$filename);
  return $sResult;
}

function retriveFromXMLTag($xml, $tag)
{
    $start_tag = "<".$tag.">";
    $end_tag   = "</".$tag.">";
    $result = "";
    $pos = strpos($xml,$start_tag);
    if ($pos === false) 
    { 
   	    $result = "";
    }else
    {
        $block = substr($xml,$pos+strlen($start_tag));             
        if(strlen(trim($block))>0)
        {  
          $pos = strpos($block,$end_tag);
          if ($pos === false) 
          { 
         	   $result = "";
          }else
          {
            $result = substr($block,0,$pos);  
          }  
        }else
        {
          $result = "";
        }
    }
    return $result;
}
}
?>
